package com.gome.ocean.service.datax;

import java.util.List;

import org.quartz.SchedulerException;

import com.github.pagehelper.Page;
import com.gome.ocean.common.exception.JobServiceException;
import com.gome.ocean.dao.model.datax.CreateJobVO;
import com.gome.ocean.dao.model.datax.JobBO;

/**
 * Created by liuqingxia on 2016/1/21.
 */
public interface JobService {

    /**
     * 插入任务
     *
     * @param createJobVO
     * @return
     * @throws SchedulerException
     */
    public boolean insertJob(CreateJobVO createJobVO) throws SchedulerException;

    /**
     * 对于cron类型的job,此方法是向quartz容器中提交job，<br>
     * 对于非cron类型的（只执行一次的任务），则报异常
     *
     * @param jobBO
     * @return
     * @throws SchedulerException
     * @throws JobServiceException
     */
    public boolean startJob(JobBO jobBO) throws SchedulerException, JobServiceException;

    /**
     * 移除任务
     *
     * @param jobBO
     * @return
     * @throws SchedulerException
     */
    public boolean removeJob(JobBO jobBO) throws SchedulerException;

    /**
     * 暂停任务
     *
     * @param jobBO
     * @return
     * @throws SchedulerException
     */
    public boolean pauseJob(JobBO jobBO) throws SchedulerException, JobServiceException;

    /**
     * 恢复任务
     *
     * @param jobBO
     * @return
     * @throws SchedulerException
     */
    public boolean resumeJob(JobBO jobBO) throws SchedulerException, JobServiceException;

    /**
     * 更新任务
     *
     * @param jobBO
     * @return
     * @throws SchedulerException
     */
    public boolean updateJob(JobBO jobBO) throws SchedulerException, JobServiceException;

    /**
     * 触发任务，如果是cron类型的直接执行 忽略表达式，立刻执行<br>
     * 如果是只执行一次的，则直接单线程执行
     *
     * @param jobBO
     * @return
     * @throws SchedulerException
     */
    public boolean triggerJob(JobBO jobBO) throws SchedulerException;

    /**
     * 终止任务的执行
     *
     * @param jobBO
     * @return
     */
    public boolean interrupt(JobBO jobBO) throws SchedulerException, JobServiceException;

    /**
     * 以下方法为查询任务
     */
    public Page<JobBO> findAllJobs(int pageNum, int pageSize) throws JobServiceException;
    
    public boolean updateJobBO(JobBO jobBO);

    public List<JobBO> findAllJobList() throws JobServiceException;

    public Page<JobBO> findJob(String submitUser, int pageNum, int pageSize) throws JobServiceException;

    public Page<JobBO> findJob(String submitUser, String projectName, int pageNum,
                               int pageSize) throws JobServiceException;

    public Page<JobBO> findJobByProjectName(String projectName, int pageNum, int pageSize) throws JobServiceException;

    public JobBO findJob(Long id);

    public Page<JobBO> findJobsByProjectNames(List<String> projectNames, int pageNum,
                                              int pageSize) throws JobServiceException;

    public Page<JobBO> findJobsByExecuteType(int type, int pageNum, int pageSize);

    public Page<JobBO> findJobsByExecuteTypeAndProjectNames(int type, List<String> projectNames, int pageNum,
                                                            int pageSize);

    public Page<JobBO> findJobsByIntroduce(String introduce, int pageNum, int pageSize);

    public Page<JobBO> findJobsByIntroduceAndProject(String introduce, List<String> projectNames, int pageNum,
                                                     int pageSize);
}
